﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YJKArchMethodLibrary.Utils;
using YJKRevitCode.ElmentSearchUtility.LinkDocumentSuite;
using YJKRGeometry;
using SectionSignAndFilled.StairsRoomSection.Kit;

namespace SectionSignAndFilled.StairsRoomSection.SignElems
{
	public class StairsRunSign
	{
		public StairsRunSign(Document Doc, List<BaseLinkDocumentResultBean> lstStairs, Line baseLine, XYZ ExternNormal)
		{
			this.m_doc = Doc;
			this.m_lstStairs = new List<BaseLinkDocumentResultBean>();
			this.m_lstStairs.AddRange(lstStairs);
			this.m_BaseLine = baseLine;
			this.m_ExternNormal = ExternNormal;
		}

		public bool Sign()
		{
			try
			{
				new List<double>();
				foreach (BaseLinkDocumentResultBean baseLinkDocumentResultBean in this.m_lstStairs)
				{
					Transform totalTransform = baseLinkDocumentResultBean.GetTotalTransform();
					Stairs stairs = baseLinkDocumentResultBean.UseElement as Stairs;
					Document document = stairs.Document;
					double num = Common.FeetToMM(stairs.ActualRiserHeight);
					double num2 = stairs.BaseElevation;
					num2 = SignCommon.TransformDouble(totalTransform, num2);
					List<ElementId> list = stairs.GetStairsRuns() as List<ElementId>;
					List<double> list2 = new List<double>();
					foreach (ElementId elementId in list)
					{
						StairsRun stairsRun = document.GetElement(elementId) as StairsRun;
						double RunBaseElev = num2 + stairsRun.BaseElevation;
						double item = num2 + stairsRun.TopElevation;
						int num3 = list2.FindIndex((double e) => YJKRGeometry.Geometry.IsEqual(RunBaseElev, e));
						if (num3 == -1)
						{
							list2.Add(RunBaseElev);
							List<double> list3 = new List<double>();
							list3.Add(RunBaseElev);
							list3.Add(item);
							Dimension dimension = SignCommon.CreateDimByElevatorAndLine(this.m_doc, list3, this.m_BaseLine, this.m_ExternNormal);
							int actualRisersNumber = stairsRun.ActualRisersNumber;
							double num4 = Common.FeetToMM(stairsRun.Height);
							string valueOverride = string.Format("{0:d}X{1:f0}={2:f0}", actualRisersNumber, num, num4);
							dimension.ValueOverride = valueOverride;
						}
					}
				}
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private Line m_BaseLine;

		private Document m_doc;

		private XYZ m_ExternNormal;

		private List<BaseLinkDocumentResultBean> m_lstStairs;
	}
}
